using System;
using System.Collections.Generic;
using System.Text;
using SharpMud.Server.Systems.Scripting.Processing.Source;

namespace SharpMud.Server.Systems.Scripting.Processing
{
    public interface IScriptCompileContext : IDisposable
    {
        bool IncludeDebugInfo { get;}
        System.Type[] GetLanguagesUsed();

        IScriptSourceHandle[] GetScripts();
        int ScriptCount { get;}
        void AddScript(IScriptSourceHandle scriptSourceHandle);
        void RemoveScript(IScriptSourceHandle scriptSourceHandle);
        void RemoveScriptAt(int index);
        bool ContainsScript(IScriptSourceHandle scriptSourceHandle);

        string[] GetAssemblyReferences();
        int AssemblyReferenceCount { get;}
        void AddAssemblyReference(string assemblyReference);
        void RemoveAssemblyReference(string assemblyReference);
        void RemoveAssemblyReferenceAt(int index);
        bool ContainsAssemblyReference(string assemblyReference);

        bool IsDirty { get;}
        void Update();

        IScriptCompileResults GetLastCompileResults(IScriptSourceHandle scriptSource);

        event System.EventHandler ContextDirtied;
        event System.EventHandler ContextSettled;

        event ScriptSourceMovedEventHandler ScriptAdded;
        event ScriptSourceMovedEventHandler ScriptRemoved;

        event ScriptCompiledEventHandler ScriptCompileAttempted;

        event System.EventHandler Disposed;
    }

    public delegate void ScriptSourceMovedEventHandler(IScriptCompileContext sender, ScriptSourceMovedEventArgs e);
    public class ScriptSourceMovedEventArgs : System.EventArgs
    {
        private IScriptSourceHandle _ScriptSource;
        
        private ScriptSourceMovedEventArgs() { }

        public ScriptSourceMovedEventArgs(IScriptSourceHandle scriptSource)
        {
            _ScriptSource = scriptSource;
        }

        public IScriptSourceHandle ScriptSource
        {
            get
            {
                return _ScriptSource;
            }
        }
    }

    public delegate void ScriptCompiledEventHandler(IScriptCompileContext sender, ScriptCompiledEventArgs e);
    public class ScriptCompiledEventArgs : System.EventArgs
    {
        private IScriptSourceHandle _ScriptSource;
        private IScriptCompileResults _ScriptCompileResults;

        public IScriptCompileResults ScriptCompileResults
        {
            get { return _ScriptCompileResults; }
        }
        public IScriptSourceHandle ScriptSource
        {
            get { return _ScriptSource; }
        }
        

        private ScriptCompiledEventArgs() {}

        public ScriptCompiledEventArgs(IScriptSourceHandle scriptSource, IScriptCompileResults scriptCompileResults)
        {
            _ScriptSource = scriptSource;
            _ScriptCompileResults = scriptCompileResults;
        }
}
}
